package com.vshop.framework.core.optionselect;

import cn.hutool.core.collection.CollUtil;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;

import java.util.List;

@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class OptionSelectUtil {

    public static <T, K> List<OptionSelect<K>> build(List<T> list, OptionSelectParser<T, K> parser) {
        if (CollUtil.isEmpty(list)) {
            return List.of();
        }
        List<OptionSelect<K>> resultList = CollUtil.newArrayList();
        list.forEach(t -> {
            OptionSelect<K> optionSelect = new OptionSelect<K>();
            parser.parse(t, optionSelect);
            resultList.add(optionSelect);
        });
        return resultList;
    }
}
